/*******************************************************************************
 * Copyright 2007, 2009 InnovaSoft SA http://www.innovasoft.biz/
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *******************************************************************************/
 
package biz.innovasoft.nodb.query;

import java.util.ArrayList;

/**
 * This class is returned by the QueryCriteria.find() methods. Contains the
 * tuples returned by the query and extra information.
 * 
 * @author Diego Miranda
 *
 */
public class Result extends ArrayList<Tuple>{

	private static final long serialVersionUID = 1L;
	
	private boolean useTemporalIndex;
	private String indexCachedId;
	
	private int totalHits;
	private int page;
	private int maxResults;
	private int minRange;
	private int maxRange;
	
	public Result () {
		super();
	}
	
	public Result (boolean useTemporal, String indexCachedId) {
		this.useTemporalIndex = useTemporal;
	}
	
	/**
	 * Returns true if the last query used a temporal index.
	 */
	public boolean getUseTemporalIndex () {
		return useTemporalIndex;
	}
	
	/**
	 * Returns the cache id identifying the query.
	 */
	public String getIndexCacheId() {
		return indexCachedId;
	}

	/**
	 * Returns the amount of hits in the index for the executed query.
	 */
	public int getTotalHits() {
		return totalHits;
	}

	public void setTotalHits(int totalHits) {
		this.totalHits = totalHits;
	}

	/**
	 * Returns the number of page retrieved.
	 * @return
	 */
	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	/**
	 * Returns the amount of objects this result contains.
	 */
	public int getMaxResults() {
		return maxResults;
	}

	public void setMaxResults(int maxResults) {
		this.maxResults = maxResults;
	}

	public int getMinRange() {
		return minRange;
	}

	public void setMinRange(int minRange) {
		this.minRange = minRange;
	}

	public int getMaxRange() {
		return maxRange;
	}

	public void setMaxRange(int maxRange) {
		this.maxRange = maxRange;
	}
	
	/**
	 * Returns the amount of pages for the executed query.
	 */
	public int getMaxPages () {
		if (totalHits > 0 && maxResults > 0) {
			if (totalHits > maxResults) {
				return (int)Math.floor ( (totalHits/maxResults) );
			}
		}
		return 0;
	}
	
}
